package com.hxzy.research.controller.adminresearch;

import com.hxzy.research.pojo.TblBigitem;
import com.hxzy.research.pojo.TblItem;
import com.hxzy.research.pojo.TblSelectvalue;
import com.hxzy.research.service.pageandmanager.FrontTeach;
import com.hxzy.research.service.research.ItemService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
public class CareerItemController {
    /**
     * 创就业满意度的增删改查
     */
    @Autowired private FrontTeach frontTeach;
    @Autowired private ItemService itemService;
    @RequestMapping("/admin/goCareerItem.go")
    public String goCareerItem(Model model,Integer pageId)throws Exception{
        //根据pageid查大项
        List<TblBigitem> bigitems= frontTeach.findBigitemByPageid(pageId);  //大项
        //通过大项id查询小项
        for (TblBigitem bigitem:bigitems){
            List<TblItem> itemList= frontTeach.findItemByBigId(bigitem.getId());
            bigitem.setSubItemVOList(itemList);

            for (TblItem item:itemList){
                List<TblSelectvalue> selectvalueList= frontTeach.findSelectvalueById(item.getId());
                item.setSelectValueVOList(selectvalueList);

            }
        }
        model.addAttribute("itemList",bigitems);
        return "admin/research/careerItem";
    }
    /**
     * 创就业的添加和修改功能共用teacher的，因为页面相同转发到同一个action
     */
    //删除
    @RequestMapping("/admin/deleteCareerSubItem.go")
    public String deleteCompSubItem(Integer id)throws Exception{
        //执行删除，先删除小项，再删除满意值表-也是通过小项id 小项id就是满意值表的item_id
        itemService.deleteItemById(id);
        itemService.deleteSelectvalue(id);
        return "redirect:goCareerItem.go?pageId=3";
    }
}
